/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package server.tools;

import server.entities.User;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import types.ResponseXML;

/**
 *
 * @author efim
 */
public class XmlHelper {
    public static InputStream Marshall(Object o) throws JAXBException, IOException
    {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        JAXBContext.newInstance(o.getClass()).createMarshaller().marshal(o, os); 
        os.flush();
        os.close();
        InputStream is = new ByteArrayInputStream(os.toByteArray());
        return is;
    }
    public static Object Unmarshall(Class t,ByteArrayOutputStream os) throws JAXBException
    {
        InputStream is = new ByteArrayInputStream(os.toByteArray());
        return JAXBContext.newInstance(t).createUnmarshaller().unmarshal(is);
    }
}
